package com.demo.servlet;

import com.demo.pojo.Goods;
import org.springframework.cglib.core.Converter;
import org.springframework.format.Formatter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.NumberFormatter;
import java.io.IOException;

@WebServlet("/addGoods.do")
public class AddGoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        Formatter
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码 防止乱码
        req.setCharacterEncoding("UTF-8");
        //参数的获取
        String goodsName = req.getParameter("goodsName");
        String goodsPrice = req.getParameter("goodsPrice");
        String goodsNumber = req.getParameter("goodsNumber");
        //进行类型转换
        Double newGoodsPrice = Double.parseDouble(goodsPrice);
        Integer newGoodsNumber = Integer.parseInt(goodsNumber);
        //封装成goods对象
        Goods goods = new Goods(goodsName, newGoodsPrice, newGoodsNumber);
        //传递
        System.out.println();
    }
}
